var initData = function(){
    Ext.get('chgpwd').on('click',function(){
        alert('chgpwd');
    });
    Ext.get('logout').on('click',function(){
        window.location = 'logon!logout.action';
    });
    Ext.get('close').on('click',function(){
        window.close();
        return false;
    });
};

var buildLayout = function(){
    var layout = new Ext.Viewport({
        layout:'border',
        items:[{
            region:'north',
            height:55,
            contentEl:'banner'
        },{
            title:'导航菜单',
            region:'west',
            width:180,
            split:true,
            collapsible:true,
            layout:'accordion',
            defaults:{autoScroll:true,border:false},
            layoutConfig:{
                animate:true
            }
        },{
            region:'center',
            contentEl:'main-div'
        }]
    });

    new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({url:'index!getMainMenus.action'}),
        reader:new Ext.data.JsonReader({},['id','title']),
        autoLoad:true
    }).on('load',function(store,records){
        var nav = layout.items.get(1);
        for (var i=0; i<records.length; i++){
        	
            var menu = new Ext.Panel({
                title:records[i].data.title,
                iconCls:'nav'
            });
            
            var root = new Ext.tree.AsyncTreeNode({
                text:records[i].data.title
            });
            
            var tree = new Ext.tree.TreePanel({
                loader:new Ext.tree.TreeLoader({dataUrl:'index!getTreeMenus.action?moduleId='+records[i].data.id}),
                root:root,
                border:false,
                rootVisible:false
            });
            tree.on('click',function(node){
                if (node.isLeaf()){
                    Ext.get('main').dom.src = node.attributes.funcUrl;
                }
            });
            menu.add(tree);
            nav.add(menu);
        }
        layout.doLayout();
    });
};

var init = function(){
    initData();
    buildLayout();
};

Ext.onReady(init);

